package com.myblog.controller;


import com.myblog.common.lang.Result;
import com.myblog.entity.BlogTags;
import com.myblog.service.BlogTagsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author From:星羽恒
 * @since 2021-11-24
 */
@RestController
@RequestMapping("/blogTags")
public class BlogTagsController {
    @Autowired
    BlogTagsService blogTagsService;

    @PostMapping("/addNewBt")
    public Result addNewBlogTag(@RequestBody BlogTags newBt){
        System.out.println(newBt.toString());
        try {
            blogTagsService.save(newBt);
            return Result.succ(newBt);
        }catch (DuplicateKeyException e){
            System.out.println("复合主键出现重复！存入失败！");
            return Result.fail("复合主键出现重复！存入失败！");
        }
    }
}
